﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GLYFrom.DiCi
{
    public partial class ToCn : Form
    {
        public ToCn()
        {
            InitializeComponent();
        }

        private void ToCn_Load(object sender, EventArgs e)
        {
            this.dataGridView1.AutoGenerateColumns = false;
            DataTable table = DBHelper.select("select * from T_TaoCan");
            this.dataGridView1.DataSource = table;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //名称
            string Name = this.text_Name.Text.Trim();
            //金额
            string Money = this.text_Money.Text.Trim();
            //sql语句
            string sql = "select * from T_TaoCan  where 1=1";
            //根据输入内容给予对应的sql语句
            if (Name.Length>0)
            {
                sql += string.Format("and TCName like '%{0}%'",Name);
            }
            if (Money.Length > 0)
            {
                sql += string.Format("and TCJG like '%{0}%'", Money);
            }
            DataTable table = DBHelper.select(sql);
            this.dataGridView1.DataSource = table;
        }

        private void 加入购物车ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //用户Id
            int Id = GeRenXX.Id;
            //下单时间
            DateTime time = DateTime.Now;
            //订单号
            //订单号
            DateTime Time = time.AddDays(GeRenXX.Id);
            string DDH = Time.ToString("yyyyMMddhhmmssfff");
            DDH += string.Format("{0}", Id);
            //商品名称
            string Name = this.dataGridView1.SelectedRows[0].Cells["Col_Name"].Value.ToString();
            //价格
            int Money = Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells["Col_JG"].Value);
            //订单状态
            int ZT = Convert.ToInt32(MeiJu.JR);
            //执行
            int sr = DBHelper.ZSG(string.Format("insert into T_DingDan values('{0}','{1}','{2}','{3}','{4}','{5}')", Id, DDH, Name, time, Money, ZT));
            if (sr > 0)
            {
                MessageBox.Show("已成功加入购物车!");
            }
            else
            {
                MessageBox.Show("加入失败...");
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            DiCi.GoWuChe from = new GoWuChe();
            from.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void pictureBox5_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
